﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SyncConfig.Dialog;
using DevComponents.DotNetBar.SuperGrid;
using AppCommon.Controls;
using AppCommon;

namespace SyncConfig.Controls
{
    public partial class ClientList : UserControlBase
    {
        public ClientList()
        {
            InitializeComponent();
            if (!DesignMode)
            {
                DataView view = new DataView(FrmMain.MainForm.TreeManipulation.dsSyncConfig.Client);
                view.RowFilter = "ClientId<>'" + Guid.Empty.ToString() + "'";
                superGridControl1.PrimaryGrid.DataSource = view;

            }
        }

        private void superGridControl1_RowDoubleClick(object sender, DevComponents.DotNetBar.SuperGrid.GridRowDoubleClickEventArgs e)
        {
            AddClient frm = new AddClient();
            try
            {
                GridRow gridRow = e.GridRow as GridRow;

                frm.DataBind(gridRow.DataItem as DataRowView);
                frm.Text = "Thông tin máy trạm";
                frm.ShowDialog();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                frm.Dispose();
            }
        }

        private void labelLinkX1_Click(object sender, EventArgs e)
        {
            AddClient frm = new AddClient();
            try
            {
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                frm.Dispose();
            }
        }

        private void labelLinkX2_Click(object sender, EventArgs e)
        {
            if (superGridControl1.PrimaryGrid.ActiveRow != null)
            {
                SyncConfigDS.ClientRow row = superGridControl1.GetCurrentRow<SyncConfigDS.ClientRow>();
                if (row != null)
                {
                    ClientConfig frmConfig = new ClientConfig();
                    frmConfig.ClientId = row.ClientId;
                    frmConfig.ShowDialog();
                    frmConfig.Dispose();
                }
            }
                   
        }
    }
}
